import 'package:flutter/material.dart';

class Input extends StatelessWidget {
  String? hintText;
  Widget? prefixIcon;
  bool obscureText;
  String errortext;
  void Function(String) onChanged;

  Input(
      {super.key,
      this.hintText,
      this.prefixIcon,
      required this.onChanged,
      this.obscureText = false,
      this.errortext = "请输入"});

  @override
  Widget build(context) {
    final controller = TextEditingController();
    controller.value = TextEditingValue(text: "测试");

    return TextFormField(
      validator: (String? val) {
        if (val == null || val.isEmpty) {
          return errortext;
        }
      },
      controller: controller,
      onChanged: onChanged,
      obscureText: obscureText,
      decoration: InputDecoration(
        hintText: hintText,
        hintStyle: const TextStyle(
          color: Colors.grey,
        ),
        prefixIcon: prefixIcon,
        filled: true,
        fillColor: const Color.fromARGB(255, 245, 245, 245),
        border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(10),
            borderSide: BorderSide.none),
      ),
    );
  }
}
